package cn.wzvtc.soft14;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * Created by linji on 2016/3/4.
 */
@RestController
@EnableAutoConfiguration
@ComponentScan
@CrossOrigin(origins = "*",methods = {RequestMethod.GET,RequestMethod.POST,RequestMethod.OPTIONS})
public class Test {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Test.class, args);
    }

    @Autowired
    KebiaoService kebiaoService;//new KebiaoService();

    @RequestMapping("/getkebiaobyweekclass")
    Object getkebiaobyweekclass(int week,String clazz) {

        return this.kebiaoService.getKebiao(week,clazz);

    }

    //@RequestMapping("/getlesson")

    @RequestMapping(value="/getlesson",produces = "application/json; charset=UTF-8")
    String getlesson(){
        return "[{\"name\":\"动态编程\"},{\"name\":\"数据分析\"},{\"name\":\"移动应用\"}]";
    }

    @RequestMapping(value="/insert")
    Object insertke(String name){
       Ke k=new Ke();
        k.setName(name);
        k.setId(UUID.randomUUID().toString());
        kebiaoService.save(k);
        return ErrorInfon.SUCCESS;  //可以运行
    }


    @RequestMapping(value="/select")
    Object select(){
      return kebiaoService.select();  //调试成功
    }

    @RequestMapping(value="/update")
    Object update(String id,String name) {
        Ke ke=this.kebiaoService.getById(id);
        ke.setName(name);
        this.kebiaoService.save(ke);
        return ErrorInfon.SUCCESS;//OOK
    }


    @RequestMapping(value="/delet")
    Object delet(String id,String name){
        Ke k=new Ke();
        k.setId(id);
       this.kebiaoService.delet(k);
        return ErrorInfon.SUCCESS;  //可以使用
    }

    @RequestMapping("/home")
    String home() {
        for (int i = 0; i < 100; i++) {
            System.out.println(i);
        }
        return "Hello World!" + "{\"a\":123}";
    }
}
